# Maintainer: Johannes Löthberg <johannes@kyriasis.com>
# Contributor: Anatol Pomozov
# Contributor: kpcyrd <git@rxv.cc>
# Contributor: Frederik “Freso” S. Olesen <freso.dk@gmail.com>
# Contributor: Ian Naval <ianonavy@gmail.com>

pkgname=kubo
pkgver=0.19.1
pkgrel=1

pkgdesc='IPFS implementation in Go'
url='https://github.com/ipfs/kubo'
arch=(loong64 x86_64)
license=(MIT)

provides=('go-ipfs')
replaces=('go-ipfs')
conflicts=('go-ipfs')

depends=(glibc)
optdepends=('fuse2: for mounting/advanced use')
makedepends=(go git)

source=(kubo-$pkgver.tar.gz::https://github.com/ipfs/kubo/releases/download/v$pkgver/kubo-source.tar.gz
        ipfs.service
        ipfs@.service)
noextract=(kubo-$pkgver.tar.gz)

sha512sums=('51a3c876377619295078ec0e8063a29390fd06451e91b922f05873cbddb12cd1b7ca476d6c950819765ed4273791d1c9b420017045d7d9dcb05357c0b637b135'
            'b1d0b2ab3008adcd2c1871fe3ff57aa27cf43d6acbd4ab330f0d2efbba661a046b9c8a8cf514ddf131c5fce93ca5d91d10d516c4f39d98f33e4ac46aee1d0abb'
            'a1254e40d0bacfceb92071de7f5331cd87cc454bf70be34e892af35dfc677fcf130903577c2a4e7fe6da6b5cedecb22dc0f73d1ad86f5aa27a8333d6bd85fe8c')

prepare() {
  mkdir -p kubo
  tar -C kubo -xf kubo-$pkgver.tar.gz
  cd kubo
}

build() {
  cd kubo

  export CGO_LDFLAGS="$LDFLAGS"
  export CGO_CFLAGS="$CFLAGS"
  export CGO_CPPFLAGS="$CPPFLAGS"
  export CGO_CXXFLAGS="$CXXFLAGS"
  export GOFLAGS="-buildmode=pie -trimpath -modcacherw"
  make build
  cmd/ipfs/ipfs commands completion bash >"$srcdir"/ipfs-completion.bash
}

package() {
  cd kubo
  install -Dm 755 cmd/ipfs/ipfs "$pkgdir/usr/bin/ipfs"
  install -Dm 644 "$srcdir"/ipfs.service "$pkgdir/usr/lib/systemd/user/ipfs.service"
  install -Dm 644 "$srcdir"/ipfs@.service "$pkgdir/usr/lib/systemd/system/ipfs@.service"
  install -Dm 644 "$srcdir"/ipfs-completion.bash "$pkgdir/usr/share/bash-completion/completions/ipfs"
  install -Dm 644 -t "$pkgdir/usr/share/licenses/$pkgname/MIT" LICENSE-MIT
  install -Dm 644 -t "$pkgdir/usr/share/licenses/$pkgname/APACHE" LICENSE-APACHE
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname" README.md
}
